package Relatorios;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.swing.JComboBox;
import javax.swing.JTable;

import com.toedter.calendar.JDateChooser;

import hibernate.dao.AgendamentoDAO;
import hibernate.dao.ClienteDAO;
import hibernate.dao.ProdutoDAO;
import hibernate.entity.Cliente;

public class CtrlRelatorio {
	
	private AgendamentoDAO ageDao = new AgendamentoDAO();
	private ClienteDAO cliDao = new ClienteDAO();
	private ProdutoDAO proDao = new ProdutoDAO();
	
	public void exportaExcelHistorico(JDateChooser dtIni, JDateChooser dtFinal, JComboBox cbCliente){
		
		Cliente c = cliDao.importaDados((String) cbCliente.getSelectedItem());
		RelatorioHistoricoExcel rHistorico = new RelatorioHistoricoExcel();
		
		try {
			rHistorico.setLista(ageDao.getHistorico(dtIni.getDate(),dtFinal.getDate(), c.getId()));
			rHistorico.geraRelatorio();
		
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}
	
	
	public void carregaTableHistorico(JDateChooser dtIni, JDateChooser dtFinal, JComboBox cbCliente, JTable tbRelatorio){
		
		Cliente c = cliDao.importaDados((String) cbCliente.getSelectedItem());
		
		try {
			tbRelatorio.setModel(new HistoricoTabelModel(dtIni.getDate(), dtFinal.getDate(), c.getId()));
			tbRelatorio.getColumnModel().getColumn(0).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(1).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(2).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(3).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(4).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(5).setPreferredWidth(130);
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void carregarCbCLiente(JComboBox cbCliente){
		for( Cliente c : cliDao.getLista()){
			cbCliente.addItem(c.getNome());
		}
	}
	
	
	public void exportaExcelMovimentacao(JDateChooser dataInicial, JDateChooser dataFinal){
		
		RelatorioMovimentacaoExcel rm = new RelatorioMovimentacaoExcel();
		try{
		rm.setLista(ageDao.getMovimentacao(dataInicial.getDate(), dataFinal.getDate()));
		rm.geraRelatorio();
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		
	}
	
	public void carregaTableMovimentacao(JDateChooser dtIni, JDateChooser dtFinal, JTable tbRelatorio){
		
		
		
		try {
			tbRelatorio.setModel(new MovimentacaoTabelModel(dtIni.getDate(), dtFinal.getDate()));
			tbRelatorio.getColumnModel().getColumn(0).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(1).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(2).setPreferredWidth(130);
			tbRelatorio.getColumnModel().getColumn(3).setPreferredWidth(130);
			
			
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void carregaCbEstoque(JComboBox cbEstoque){
		cbEstoque.addItem("");
		cbEstoque.addItem("Quantidade em Estoque");
	}
	
	
	public void carregaTableEstoque( JTable tbEstoque){
		
		
		try {
			tbEstoque.setModel(new EstoqueTabelModel());
			tbEstoque.getColumnModel().getColumn(0).setPreferredWidth(130);
			tbEstoque.getColumnModel().getColumn(1).setPreferredWidth(130);
			tbEstoque.getColumnModel().getColumn(2).setPreferredWidth(130);
			
		
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void exportaExcelEstoque(){
		
		RelatorioEstoqueExcel re = new RelatorioEstoqueExcel();
		try{
		re.setLista(proDao.getListaProdutos());
		re.geraRelatorio();
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		
	}
}
